#include "data.h"

non_tabu_move(int tabu_size,  int jobs, 
			  deque <int> &siter, deque <int> &maxl) {

	int i, j, first, second ;
	deque <int> tmpl,tmpsiter;
	vector <bool> tabus, tabubit;
	bool tmptabu, tabu;	
	for ( j = 0; j <jobs; j++) 
			tmpsiter.push_back(0);	
	for ( j = 0; j <jobs; j++) {
		tmpsiter[j] = siter[j];
	}

	do{
		do{
			first = rand() / (RAND_MAX / jobs + 1);
			second = rand() / (RAND_MAX / jobs + 1);
		}while (first == second);
		swap(tmpsiter[first], tmpsiter[second]);
		
		for ( j = 0; j < jobs; j ++ )
			tabubit.push_back(0);
		tabus.clear( );
		for ( i = 0; i < tabu_size; i ++ ) {
			tmpl.clear();	
			tmptabu = 1;
			for ( j = 0; j < jobs; j ++ ) {	
				tmpl.push_back( maxl [ i * jobs + j]);
				if ( tmpl[j] == tmpsiter[j])
					tabubit[j] = 1;
				else
					tabubit[j] = 0;
				
				tmptabu = tmptabu && tabubit[j];
			}
			tabus.push_back(tmptabu);
		}
		tabu = 0;
		for ( i = 0; i < tabu_size ; i ++ )
			tabu = tabu || tabus[i];
	} while (tabu);
	
	if (!tabu) {
		for ( i = 0; i < jobs ; i ++) {
			maxl.pop_front();
			maxl.push_back( tmpsiter[i] );
		}
	}

	/*
	for ( i = 0; i < tabu_size; i ++) {
		for ( j = 0; j < jobs; j ++) {
			cout << maxl[ i * jobs + j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	*/
	
	siter.clear();
	for ( j = 0; j < jobs; j ++) {
		siter.push_back(tmpsiter[j]);
	}
	return 0;
}